import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { InjectRepository } from "@nestjs/typeorm";
// 连接数据库 中的表
import { Repository } from 'typeorm'
import { stocks } from './entities/stocks.entity'
// 声明文件操作系统对象
const fs = require('fs');
const http = require('http');
import { interval } from 'rxjs';
import { map } from 'rxjs/operators';
import * as colors from 'colors'
// const httpProxy = require('http-proxy')

import rp from 'request-promise'
// const request = require('request')
const syncRequest = require('sync-request') // 三方数据异步请求
const requests = require('./utils/request') // 请求集合


// 用 Injectable 来注释
@Injectable()
export class AppService {
  constructor(
    @InjectRepository(stocks)
    private readonly jyDataRepository: Repository<stocks>,
  ){}
  
  getHello(query): string {
    // 腾讯接口测试
    // requests.txRequestAxios().then(res => {
    //   return res.filterData
    // })
    
    // 获取页面
    // const aaa = requests.getDoc();

    // 同步请求
    let axiosData = requests.getAsyncTx()
    // console.log(axiosData.filterData, 'axiosData')

    return 'Hello World !!!!! ' + axiosData.completeData + axiosData.filterData
  }

  getOut( name ): string {
    // 数据库连接还需要 DAO data access object
    // name: string
    return 'say goodbye out ~'+ '传递的query ~ '+ name
  }

  getSse() {
    let int = 0
    return interval(1000).pipe(
      map((_) => ({
        // type: 'sse', // 这里设置了type字段的值
        data: {
          hello: 'world',
          id: int++
        }
      })),
    );
  }
}
